package com.itheima.d5_resource;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/*
     目标：掌握释放资源的方式。
 */
public class Test2 {
    public static void main(String[] args)  {}

    public static void copy2()  {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream("D:\\AAA\\壁纸\\wallhaven\\wallhaven-m3zx3m_1920x1080.png");
            fos = new FileOutputStream("B.png");
            byte[] bytes = new byte[1024];
            int byt;
            while ((byt = fis.read(bytes)) != -1) {
                fos.write(bytes, 0, byt);
            }
        } catch (Exception e) {
           e.printStackTrace();
        }finally {
            if(fis != null){
                try {
                    fis.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                try {
                    fos.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
